package com.xaut.outpatientsystem.medicinalManagement.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xaut.outpatientsystem.medicinalManagement.pojo.User;
import com.xaut.outpatientsystem.medicinalManagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/getUserInfo")
    public User getUserInfo(Integer userId) {
        User user = userService.getById(userId);
        return user;
    }

    @PostMapping("/getUserByAge")
    public User getUserByAge(int age) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("age", age);
        User user = userService.getOne(queryWrapper);
        return user;
    }

    @PostMapping("/getUserListByAgeLimit")
    public List<User> getUserListByAgeLimit() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("age", 20);
        queryWrapper.lt("age",90);
        List<User> userList = userService.list(queryWrapper);
        return userList;
    }
}
